updating oE copy

copy

include map.e 
namespace map 
public function copy(map source_map, object dest_map = 0, integer put_operation = PUT) 

duplicates a map.

Parameters:
  1. source_map : map to copy from
  2. dest_map : optional, map to copy to
  3. put_operation : optional, operation to use when dest_map is used. The default is PUT.
Returns:

If dest_map was not provided, an exact duplicate of source_map otherwise dest_map, which does not have to be empty, is returned with the new values copied from source_map, according to the put_operation value.

Example 1:
map m1 = new() 
put(m1, 1, "one") 
put(m1, 2, "two") 
 
map m2 = copy(m1) 
printf(1, "%s, %s\n", { get(m2, 1), get(m2, 2) }) 
-- one, two 
 
put(m1, 1, "one hundred") 
printf(1, "%s, %s\n", { get(m1, 1), get(m1, 2) }) 
-- one hundred, two 
 
printf(1, "%s, %s\n", { get(m2, 1), get(m2, 2) }) 
-- one, two 
Example 2:
map m1 = new() 
map m2 = new() 
 
put(m1, 1, "one") 
put(m1, 2, "two") 
put(m2, 3, "three") 
 
copy(m1, m2) 
 
? keys(m2) 
-- { 1, 2, 3 } 
Example 3:
map m1 = new() 
map m2 = new() 
 
put(m1, "XY", 1) 
put(m1, "AB", 2) 
put(m2, "XY", 3) 
 
pairs(m1) --> { {"AB", 2}, {"XY", 1} } 
pairs(m2) --> { {"XY", 3} } 
 
-- Add same keys' values. 
copy(m1, m2, ADD) 
 
pairs(m2) --> { {"AB", 2}, {"XY", 4} } 
See Also:

put

Not Categorized, Please Help

Search



Quick Links

User menu

Not signed in.

Misc Menu